<template>
  <div>
    <h1>会员列表</h1>

    <!-- 分页条 -->
    <el-pagination
      background
      :total="total"
      :current-page="page"
      :page-size="pagesize"
      @current-change="changePage"
    ></el-pagination>

    <!-- 表格 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column prop="id" label="编号"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="age" label="年龄"></el-table-column>
      <el-table-column prop="sex" label="性别"></el-table-column>
      <el-table-column prop="email" label="邮箱"></el-table-column>
      <el-table-column prop="tel" label="电话"></el-table-column>
      <el-table-column prop="expense" label="消费金额"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="success"
            @click="
              $router.push({
                name: '收货地址管理',
                query: { id: scope.row.id },
              })
            "
            >查看收货地址</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { fetchUser } from "@/api/user";
export default {
  created() {
    this.loadData();
  },
  data() {
    return {
      tableData: [],
      total: 0,
      page: 1,
      pagesize: 10,
      // 表格是否显示loading图
      loading: false,
    };
  },
  methods: {
    changePage(page) {
      this.page = page;
      this.loadData();
    },
    async loadData() {
      // 显示loading图
      this.loading = true;

      // Ajax
      const res = await fetchUser({
        page: this.page,
        pagesize: this.pagesize,
      });

      // 设置data
      this.tableData = res.results;
      this.total = res.total;

      // 取消loading图
      this.loading = false;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>